<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>登录</title>
    <script src="js/constant.js"></script>
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <link rel="icon" href="">
</head>
<script>
    //后台接口地址
    var interfaceAddress = getAddress();
    $(document).ready(function () {
        $("#ajaxLogin").click(function () {
            $.ajax({
                type: "POST",
                url: interfaceAddress + "/login/in",
                contentType: "application/json; charset=utf-8",
                xhrFields: {
                    withCredentials: true
                },
                data: JSON.stringify(GetJsonData()),
                dataType: "json",
                success: function (message) {
                    if (true === message.success) {
                        window.location.href = "/index";
                    } else {
                        alert("登录失败 > " + message.errorMsg)
                    }
                },
                error: function (message) {
                    alert("请求服务失败");
                }
            });
        });
    });

    function GetJsonData() {
        var json = {
            "username": $("#username").val(),
            "password": $("#password").val()
        };
        return json;
    }
</script>
<body>
<p>账号：<input type="text" name="username" id="username" value="admin"/></p>
<p>密码：<input type="text" name="password" id="password" value="123456"/></p>
<p id="errorMsg"></p>
<p><input type="button" value="登录" id="ajaxLogin"/></p>
</body>
</html>
